<template>
	<view>
		<view class="u-page min-h75">
			<page-nav :title="xasaGlob.appName" :subtitle="xasaGlob.appAlias"></page-nav>
			<view class="m-t-20">
				<!--:to="`./list?menu_id=${menu.menu_id}&c=${item1._id}&t=${item1.text}`"-->
				<uni-list>
					<uni-list-item v-for="(item1, index1) in categories" 
					clickable showArrow :thumb="item1.icon"
						thumb-size="sm" :title="item1.text" 
						@click="toListPage(item1)" :key="index1">
					</uni-list-item>
				</uni-list>
			</view>
		</view>
		<xasa-foot></xasa-foot>
	</view>
</template>
<script>
	import {
		getXasaGlob
	} from '@/js_sdk/xasaGlobData';

	const db = uniCloud.databaseForJQL();

	export default {
		data() {
			return {
				menu: null,
				xasaGlob: {
					appName: '',
					appAlias: '',
					cloudDownDomain: ''
				},
				mtitle: '内容分类列表',
				categoryText: '',
				"categories": []
			}
		},
		watch: {
			mtitle: {
				handler(n, o) {
					uni.setNavigationBarTitle({
						title: `${this.mtitle}`
					})
				},
				immediate: true
			}
		},

		async onLoad(e) {
			const menuId = e.menu_id;
			if (menuId) {
				this.menu = this.$xasaStore.findMenu(menuId)

			}
			const that = this;
			//this.getOpenerEventChannel().on('E_HandleMenu', function(data) {
			//	that.mtitle = data.name || that.mtitle
			//})
			let appName = await getXasaGlob('appName');
			let appAlias = await getXasaGlob('appAlias');
			let cloudDownDomain = await getXasaGlob('cloudDownDomain');
			this.xasaGlob = {
				appName: appName,
				appAlias: appAlias,
				cloudDownDomain: cloudDownDomain
			}
			this.$xasaStore.getCats().then(res => {
				this.categories = res.data
			})
			/* db.collection('xasa-categories')
				.field('_id,name,icon,sort')
				.orderBy('sort')
				.get().then(res => {
					this.categories = res.data
				}).catch(err => {
					console.error(err)
				}) */
			//db.collection('xasa-categories').field('_id as value,name as text,icon').get()
			//console.log('cloudDomain', process.env.VUE_APP_CLOUD_DOMAIN);
		},
		onShow() {

		},

		onReady() {
			if (this.menu) {
				uni.setNavigationBarTitle({
					title: this.menu.name
				})
			}
		},

		methods: {
			toListPage(item) {
				let url = `./list?menu_id=${this.menu.menu_id}&c=${item._id}&t=${item.text}`;
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	/* page {
		background-color: rgb(240, 242, 244);
	} */
</style>

<style lang="scss" scoped>
	.u-cell-icon {
		width: 36rpx;
		height: 36rpx;
		margin-right: 8rpx;
	}

	.m-t-20 {
		margin-top: 0px;
	}
</style>